package io.jft.doll.model.viewModel

import android.arch.lifecycle.MutableLiveData
import com.g.base.extend.switchMap
import com.g.base.viewModel.BaseViewModel
import com.google.gson.JsonObject
import io.jft.doll.room.repository.GameHistoryRepository

/**
 * Created by G on 2017/12/5 0005.
 */
class GameHistoryViewModel : BaseViewModel() {

    private val gameRepository by lazy { GameHistoryRepository() }
    private val operateGameHistory by lazy { MutableLiveData<JsonObject>() }
    val gameHistorySize = 20

    fun operateGameHistory(offset: Int, roomId: String = "-1") {
        operateGameHistory.value =
                JsonObject().apply {
                    addProperty("offset", offset.toString())
                    addProperty("limit", gameHistorySize.toString())
                    addProperty("limitRoomId", roomId)
                }
    }

    fun obsGameHistoryList() = operateGameHistory.switchMap {
        gameRepository.getGameHistoryList(it)
    }

    fun postFeedback(id: String, reason: String) =
            gameRepository.postGameFeedback(JsonObject().apply {
                addProperty("id", id)
                addProperty("reason", reason)
            })
}